
/*
   如何用NSLog输出NSRange,CGRect等结构体。
   比如:NSLog(@"rect1: %@", NSStringFromCGRect(rect1));

   使用对应的转换
   NSStringFromCGPoint   NSStringFromCGSize   NSStringFromCGRect   NSStringFromCGAffineTransform   NSStringFromUIEdgeInsets
   */


NSArray *allSubviews(UIView *aView);
NSArray *allApplicationViews();
NSArray *pathToView(UIView *aView);

#ifdef DEBUG

//filename fun(line) agrs...
#define Log(fmt, ...) do {\
    NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \
    NSLog((@"%@ %s(%d) " fmt), [file lastPathComponent], __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); \
    [file release]; \
} while(0)

//fun(line) agrs...
#define log(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#define LogFun Log(@"")
#define LogFunS Log(@"==>start")
#define LogFunE Log(@"==>end")
#define LogCount(str, p) Log(@"%@,retainCount = %d", str, [p retainCount])
#define LogCF CFShow 

//打印view树日志
#define LogView(view) \
    NSLog(@"the view's subviews:"); \
    CFShow(allSubviews(view))

#define LogAllView() \
    NSLog(@"application window subviews:"); \
    CFShow(allApplicationViews())	

#define LogParentView(subview) \
    NSLog(@"path of the view:"); \
    CFShow(pathToView(subview))

#define LogStr(str) Log(@"%@", str)
#define LogRange(str, range) Log(@"%@%@", str, NSStringFromRange(range))
#define LogPoint(str, point) Log(@"%@%@", str, NSStringFromCGPoint(point))
#define LogSize(str, size) Log(@"%@%@", str, NSStringFromCGSize(size))
#define LogRect(str, rect) Log(@"%@%@", str, NSStringFromCGRect(rect))


#else

#define Log(...)
#define log(...)
#define LogFun
#define LogFunS
#define LogFunE
#define LogCount(p)

#define LogCF
#define LogView(view)
#define LogAllView()
#define LogParentView(subview)

#define LogStr(str)
#define LogRange(str, range)
#define LogPoint(str, point)
#define LogSize(str, size)
#define LogRect(str, rect)

#endif





/*
//真机日志文件
//==========================================================
- (void)redirectNSLogToDocumentFolder{
// 把stderr重定向到该app的Document/curdata.log文件中
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// 真机测试时保存日志
if ([CDeviceInfo getModelType] != SIMULATOR) {
[self redirectNSLogToDocumentFolder];
}
}


//模拟器日志文件
//==========================================================
- (void)redirectNSLogToDocumentFolder{
//模拟器测试时，可以把stderr重定向到任何文件（已经测试），如~/wwp.log
NSString *logFilePath = @"~/wwp.log";
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self redirectNSLogToDocumentFolder];
}

*/
